package ctgu.yao.cloud.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import ctgu.yao.cloud.dto.ResultDTO;
import ctgu.yao.cloud.po.Company;
import ctgu.yao.cloud.po.Recruitment;
import ctgu.yao.cloud.service.CompanyService;
import ctgu.yao.cloud.util.ResultDTOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Y
 * @since 2022-08-16
 */
@RestController
@RequestMapping("/company")
public class CompanyController {
    @Autowired
    private CompanyService companyService;
    //添加公司信息
    @PostMapping("/insert/{cuid}")
    public ResultDTO publish(@RequestBody Company company,@PathVariable("cuid") Integer cuid){
        boolean save = this.companyService.save(company,cuid);
        if(save) return ResultDTOUtil.fail();
        return ResultDTOUtil.success(null);
    }
    //查看自己公司信息
    @GetMapping("/list/{cuid}")
    public ResultDTO list(@PathVariable("cuid") Integer cuid){
        QueryWrapper<Company> queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("cuid",cuid);
        List<Company> company = this.companyService.list(queryWrapper);
        return ResultDTOUtil.success(company);
    }
    //修改公司信息
    @GetMapping("/findById/{cpId}")
    public ResultDTO findByID(@PathVariable("cpId") Integer cpId){
        Company company = this.companyService.getById(cpId);
        return ResultDTOUtil.success(company);
    }
    @PutMapping("/update")
    public ResultDTO update(@RequestBody Company company){
        boolean update=this.companyService.updateById(company);
        if(!update) return ResultDTOUtil.fail();
        return ResultDTOUtil.success(null);
    }
    //公司信息删除
    @DeleteMapping("/deleteById/{id}")
    public ResultDTO deleteById(@PathVariable("id") Integer id) {
        boolean delete = this.companyService.removeById(id);
        if (!delete) return ResultDTOUtil.fail();
        return ResultDTOUtil.success(null);
    }

}
